package main

import (
	"fmt"
	"gitee.com/thomasgw/rabbitMQ-demo/mq"
	"gitee.com/thomasgw/rabbitMQ-demo/client"
)

func main(){
	//By operating Exchanger to register clients.
	exch := mq.NewExchanger(5672)
	err := exch.Start()
	if err != nil {
		return
	}
	routingKeys := make([]string,0)
	routingKeys = append(routingKeys, "ADD")
	routingKeys = append(routingKeys, "MINUS")
	exch.Subscribe(routingKeys)
	fmt.Println(exch.GetCManager().GetClient(routingKeys).GetQueueCount())

	//create Emitter and emit events.
	emitter := mq.NewEventEmitter(exch.DataCh)
	go emitter.EmitAdd(3,4)
	go emitter.EmitMinus(9,1)
	go emitter.EmitAdd(10,15)

	//client listen on channel
	c := exch.GetCManager().GetClient(routingKeys)
	go c.PublishMessage()

	for{
		output(c)
	}
}

func output(client *client.Client) {
	value := <-client.GetChannel()
	fmt.Println(value)
}